package com.thread.www.demo;

/**
 * Created by wangyang on 2017/10/23.
 */
public class VolatileMain {
    static volatile int i = 0;
    public static class PluginTask implements Runnable{
        @Override
        public void run() {
            for (int k = 0; k <10000 ; k++) {
                i++;
            }
        }
    }

    public static void main(String[] args) {
        Thread[] threads = new Thread[10];
        for (int j = 0; j <10 ; j++) {
            threads[j] = new Thread(new PluginTask());
            threads[j].start();
        }
        for (int j = 0; j <10 ; j++) {
            try {
                threads[j].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(i);
    }
}
